<?php

namespace App\Http\Models\Report;

use App\Http\Models\SalesRegion;

class RegionKeyProduct extends SalesRegion
{
    //键值为category_key_product_id 的值
    //键名为台数
    public $invoice_target_key_product = [];

    //键值为category_key_product_id 的值
    //键名为台数 
    public $invoice_real_key_product = [];


    public function getTargetById(int $key_product_id)
    {
        $result = 0;
        if (array_key_exists($key_product_id, $this->invoice_target_key_product)) {
            $result = $this->invoice_target_key_product[$key_product_id];
        }
        return $result;
    }


    public function getRealById(int $key_product_id)
    {
        $result = 0;
        if (array_key_exists($key_product_id, $this->invoice_real_key_product)) {
            $result = $this->invoice_real_key_product[$key_product_id];
        }
        return $result;
    }


    public function getProgressById(int $category_key_product_id)
    {
        $result = 0;
        $real = 0;
        if (array_key_exists($category_key_product_id, $this->invoice_real_key_product)) {
            $real = $this->invoice_real_key_product[$category_key_product_id];
        }
        $target = 0;
        if (array_key_exists($category_key_product_id, $this->invoice_target_key_product)) {
            $target = $this->invoice_target_key_product[$category_key_product_id];
        }
        if ($target != 0) {
            $result = $real / $target;
        }
        return $result;
    }
}
